local IsClient = game:GetService("RunService"):IsClient();
local M=nil
if  IsClient then
    M=_G.ClientOHOH.class.new(script, _G.ClientOHOH.files.Client_PlayerComponent());
else
    M=_G.ServerOHOH.class.new(script,  _G.ServerOHOH.files.Server_PlayerComponent());
end


function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);	

    self.player=self.parent.player

    if  IsClient then
        
        self.DataStore=self.player:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())
        self.player.UserDataEvent:Connect(function(data)
            if data["weapon"]   then
                self:Update()
            end;
        end);

    else

        self.DataStore=self.player:GetComponent(_G.ServerOHOH.load.Server_PlayerDataComponent())
        self.player.UserDataEvent:Connect(function(key)
            if key=="weapon"then
                self:Update()
            end;
        end);

    end

    self:AddProcess(function()
        self:Wait(0.2)
        self:Update()
    end)
    
end;

function M.dtor(self)
    if self.Weapon then
        self.Weapon:dtor()
        self.Weapon=nil
    end
	M.super.dtor(self);
end;


function M.GetWeapon(self)
    return self.Weapon
end


--更新武器
function M.Update(self)
    local equidId=self.DataStore:GetData("weapon").equip
     if not self.Weapon then
        self.Weapon=_G.CommonOHOH.load.PlayerBow().new(equidId,self.player.character,self.player)
     else
        if self.Weapon:IsEqual(equidId) then
            self.Weapon:UpdateLevelByEquipId(equidId)
        else
            self.Weapon:dtor()
            self.Weapon= _G.CommonOHOH.load.PlayerBow().new(equidId,self.player.character,self.player)
        end
     end
 end

 
--客户端同步
-- arg={
--     equipId=self:GetEquipId(),
--     actionId="StartAttack",
--     arg={}
-- }
 function M.SynWeaponOP(self,arg)
    if  self.Weapon then
        self.Weapon[arg.actionId](self.Weapon,arg.arg)
    end
 end

 

return M